package com.ado.bazinga.core.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import com.ado.bazinga.core.dal.entity.User;
import com.ado.bazinga.core.manager.UserManager;
import com.ado.bazinga.core.service.UserService;

/**
 *@author adonais
 *@date 2020年3月22日
 *@description UserServiceImpl.java  用户操作接口实现
 **/
@Service(value = "userService")
public class UserServiceImpl implements UserService{
	
	@Autowired
	@Qualifier(value = "userManager")
	private UserManager userManager ;

	@Override
	public User findByEmail(String email) {
		User user = new User() ;
		if (!(StringUtils.isEmpty(email))) {
			user = userManager.findUserByEmail(email) ;
		}
		return user;
	}

	@Override
	public boolean createUser(User user) {
		boolean flag = userManager.save(user);
		return flag;
	}

	@Override
	@Transactional
	public boolean updateUser(User user) {
		boolean flag = userManager.updateById(user) ;
		return flag;
	}

	@Override
	public User findUserById(Integer id) {
		User user = userManager.getById(id) ;
		return user;
	}

	@Override
	@Transactional
	public boolean deleteUserById(Integer userId) {
		boolean flag = userManager.removeById(userId) ;
		return flag;
	}

	@Override
	public List<User> getAllUsers() {
		List<User> users = userManager.list() ;
		return users;
	}

}
